

PLATFORM=3519     # 目标平台
BUILDTYPE=Release    # 编译类型
TOOLCHAIN=himix200
CUR_PATH=`pwd`

set -e
usage() {
    echo "Usage: $0 bj(area) [-0(yolov5),1(yolov7),2(yolov5_only_plate),3(yolov5_with_plate),4(yolov5_only_plate_car)](model) [-false/true](log_debug)"
    exit 1
}

if [ $# -lt 1 ]; then
    usage
fi

AREA=$1

YOLO_VERSION=0
CLASS_NUM=80
LANDMARK_NUM=0
LOG_DEBUG_LEVEL=false

if [ -n "$2" ]; then
    YOLO_VERSION=$2
    # yolov5_only_plate
    if [ $YOLO_VERSION = 2 ]; then
        CLASS_NUM=1
        LANDMARK_NUM=8
    fi
    # yolov5_with_plate
    if [ $YOLO_VERSION = 3 ]; then
        CLASS_NUM=81
    fi
    # yolov5_only_plate_car
    if [ $YOLO_VERSION = 4 ]; then
        CLASS_NUM=3
        LANDMARK_NUM=8
    fi
fi

if [ -n "$3" ]; then
    LOG_DEBUG_LEVEL=$3
fi

printf -v date_time '%(%Y%m%d%H%M)T' -1
BUILD_INFO=build.${date_time}
BUILD_TS=`date '+%s'`

# set -e
# usage() {
#     echo "Usage: $0 3559 Release"
#     echo -e "\t 3559 or 3516/3519"
#     echo -e "\t build type (debug/release), lib_type (dynamic/static), build all when unspecify"
#     exit 1
# }

clear(){
    rm -rf ./build-hisi$PLATFORM-linux/CMakeCache.txt
    mkdir -p build-hisi$PLATFORM-linux
    pushd build-hisi$PLATFORM-linux
}

# if [ $# -ge 1 ]; then
#     PLATFORM=$1
#     shift 1
# fi

# if [ $# -ge 1 ]; then
#     BUILDTYPE=$1
#     shift 1
# fi

if [ "$PLATFORM" == "3559" ]; then
    TOOLCHAIN=himix100
elif [ "$PLATFORM" == "3516" ] || [ "$PLATFORM" == "3519" ]; then
    TOOLCHAIN=himix200
else
    echo "ERR: pelease check your platform"
    usage
fi

echo "+++++++++++++++++++++++++++++"
echo "AREA              : $AREA"
echo "BUILD_INFO        : $BUILD_INFO"
echo "BUILD_TS          : $BUILD_TS"
echo "YOLO_VERSION      : $YOLO_VERSION"
echo "CLASS_NUM         : $CLASS_NUM"
echo "LANDMARK_NUM      : $LANDMARK_NUM"
echo "LOG_DEBUG_LEVEL   : $LOG_DEBUG_LEVEL"
echo "CUR_PATH          : $CUR_PATH"
echo "PLATFORM          : $PLATFORM"
echo "BUILDTYPE         : $BUILDTYPE"
echo "+++++++++++++++++++++++++++++"

# 清除缓存文件
clear

cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/$TOOLCHAIN.toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILDTYPE -DHWAPP_BUILD_PLATFORM=$PLATFORM -DAREA=$AREA -DBUILD_INFO=$BUILD_INFO -DBUILD_TS=$BUILD_TS -DLOG_DEBUG_LEVEL=$LOG_DEBUG_LEVEL -DYOLO_VERSION=$YOLO_VERSION -DCLASS_NUM=$CLASS_NUM -DLANDMARK_NUM=$LANDMARK_NUM ..
make -j8
popd
exit 0